package utils

import (
	"github.com/go-redis/redis"
	"longmen/server/config/global"
)

func Pipeline(execute func(p redis.Pipeliner)) {
	pipeline := global.GetRds().Pipeline()
	execute(pipeline)
	exec, err := pipeline.Exec()
	if err != nil {
		global.Log.Error("redis Pipeline excute match to redis error: ", err)
		return
	}
	for _, cmder := range exec {
		switch cmd := cmder.(type) {
		case *redis.BoolCmd:
			_, err := cmd.Result()
			if err != nil {
				global.Log.Error("redis Pipeline err: ", err)
			}
		case *redis.StatusCmd:
			_, err := cmd.Result()
			if err != nil {
				global.Log.Error("redis Pipeline err: ", err)
			}
		default:
			global.Log.Errorf("redis Pipeline Unknown cmd: %#v", cmd)
		}

	}
}
